# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator
from contextlib import ExitStack

jms_dws__dws_centersend_timerate_summary_dt = SparkSubmitOperator(
    task_id='jms_dws__dws_centersend_timerate_summary_dt',
    email=['wangmenglei@jtexpress.com','yl_bigdata@yl-scm.com'],
    pool_slots=2,
    # depends_on_past=True,  # 如果任务依赖于前一天的同名任务，则将 depends_on_past 设为 True
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='jms_dws__dws_centersend_timerate_summary_dt_{{ execution_date | date_add(1) | cst_ds }}',  # yarn 任务名称
    driver_memory='2G',
    executor_memory='8G',
    executor_cores=4,
    num_executors=10,
    conf={'spark.executor.memoryOverhead': 2048,
          'spark.core.connection.ack.wait.timeout': 300,
          'spark.default.parallelism': 600,
          'spark.locality.wait': 60,
          },
    # jars='hdfs:///user/oozie/chenhoukun/report/centersend_timerate_data/pro/common-1.0-SNAPSHOT.jar',  # 依赖 jar 包
    jars='hdfs:///scheduler/jms/spark/chk/report/centersend_timerate_data/pro/common-1.0-SNAPSHOT.jar',  # 依赖 jar 包
    java_class='com.yunlu.bigdata.jobs.report.CenterSendTimerateSummaryDataNew',  # spark 主类
    application='hdfs:///scheduler/jms/spark/chk/report/centersend_timerate_data/pro/original-jobs-1.0-SNAPSHOT.jar',
    # application='hdfs:///user/oozie/chenhoukun/report/centersend_timerate_data/pro/original-jobs-1.0-SNAPSHOT.jar',  # spark jar 包
    # spark jar 包
    application_args=['{{ execution_date  | date_add(1)| cst_ds }}'],  # 参数dt 2020-10-26
)

# 设置上游依赖
def set_deps():
    from jms.dwd.dwd_centersend_timerate_detail_dt import jms_dwd__dwd_centersend_timerate_detail_dt

# 设置依赖
    jms_dws__dws_centersend_timerate_summary_dt << [ jms_dwd__dwd_centersend_timerate_detail_dt ]

# 延迟执行设置上游依赖，避免 import python 包的时候其他 Operator 尚未加载完成引起的循环依赖错误
with ExitStack() as stack:
    stack.callback(set_deps)